package com.lyl.momanapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lyl.momanapp.R;
import com.lyl.momanapp.bean.ShopCarBean;
import com.lyl.momanapp.bean.URL;

import org.xutils.x;

import java.util.ArrayList;

/**
 * 名字 梁亚龙
 * 时间 2017/12/4.
 * QQ邮箱 503934353@qq.com
 */

public class ShopCar extends BaseAdapter {
    private LayoutInflater mInflater;
    private Context context;
    private ArrayList<ShopCarBean.ResultBean.GoodsBean.VaildBean> list;

    public ShopCar(Context context, ArrayList<ShopCarBean.ResultBean.GoodsBean.VaildBean> list) {
        this.mInflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ShopCarBean.ResultBean.GoodsBean.VaildBean vaildBean = list.get(position);
        ShopCar.ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ShopCar.ViewHolder();
            convertView = mInflater.inflate(R.layout.item_shop_car, null);
            viewHolder.name = convertView.findViewById(R.id.shop_car_name);
            viewHolder.price = convertView.findViewById(R.id.shop_car_price);
            viewHolder.shop = convertView.findViewById(R.id.shop_car_shop);
            viewHolder.num = convertView.findViewById(R.id.shop_car_num);
            viewHolder.img = convertView.findViewById(R.id.shop_car_img);
            convertView.setTag(vaildBean);

        } else {
            viewHolder = (ShopCar.ViewHolder) convertView.getTag();
        }
        viewHolder.name.setText(vaildBean.getName());
        viewHolder.price.setText(vaildBean.getPrice());
        viewHolder.num.setText(vaildBean.getQuantity()+"");
        x.image().bind(viewHolder.img, URL.APPimgURL + vaildBean.getProduct_image());

        return convertView;

    }

    class ViewHolder {
        private ImageView img;
        private TextView name, price, shop, num;

    }
}
